<?php
class Pencarian extends CI_Controller {

	function __construct()
	{
		parent::__construct();	
		$this->load->library('form_validation');
		$this->load->helper('generate_pdf');
		
		$this->load->model('user_man_model');
		$this->load->model('anggaran_model');
				
		$this->load->model('program_model');
		$this->load->model('user_man_model');
		$this->load->model('unit_organisasi_model');
		$this->load->model('pencarian_model');
		$this->load->model('pencarian_model_keg');
		if(function_exists("date_default_timezone_set") and function_exists("date_default_timezone_get"))
                    @date_default_timezone_set(@date_default_timezone_get());
	}
	
	
	function form_pencarian()
    {
		
		//if ($this->cek_validasi() == FALSE){
				$data['status'] = 'new';
				$data['anggaran'] = $this->anggaran_model->get_anggaran();
				$data['content'] = $this->load->view('form_pencarian',$data,true);
				$this->load->view('main',$data);
			//}
			//else{
			//	$this->cari();
			//}            
    }
	
	function cek()
	{
		if ($this->cek_validasi() == FALSE){
			$this->form_pencarian();
		}
		else{
			$this->cari();
		}
	}
	
	
	
	function get_program(){
		if ($_POST['tahun']!='' && $_POST['tahun']!='0') //$_POST['first_select'] is the post variable you sent via AJAX call
        {
        	$tahun = $_POST['tahun'];
			$data = $this->pencarian_model->get_program($tahun);
			$options.= '<option value="0">-- Pilih Semua --</option>';
			foreach ($data->result() as $row)
				{
					$options.= '<option value="'.$row->IDPROGRAM.'" class="dynamic">'.$row->DESKRIPSI.'</option>';
				}        
			echo $options;
        }
		else {
		echo '<option value="0">-- Pilih Semua --</option>';}
	}
	
	function get_sasaran_program(){
		if ($_POST['program']!='' && $_POST['program']!='0') //$_POST['first_select'] is the post variable you sent via AJAX call
        {
        	$program = $_POST['program'];
			$data = $this->pencarian_model->get_sasaran($program);
			$options.= '<option value="0">-- Pilih Semua --</option>';
			foreach ($data->result() as $row)
				{
					$options.= '<option value="'.$row->IDSASARAN_PROG.'" class="dynamic">'.$row->DESKRIPSI.'</option>';
				}        
			echo $options;
        }
		else {
		echo '<option value="0">-- Pilih Semua --</option>';}
	}
	
	function get_indikator_program(){
		if ($_POST['sasaran_prog']!='' && $_POST['sasaran_prog']!='0') //$_POST['first_select'] is the post variable you sent via AJAX call
        {
        	$sasaran_prog = $_POST['sasaran_prog'];
			$data = $this->pencarian_model->get_indikator($sasaran_prog);
			$options.= '<option value="0">-- Pilih Semua --</option>';
			foreach ($data->result() as $row)
				{
					$options.= '<option value="'.$row->IDINDIKATOR_PROG.'" class="dynamic">'.$row->DESKRIPSI.'</option>';
				}        
			echo $options;
        }
		else {
		echo '<option value="0">-- Pilih Semua --</option>';}
	}
	
	function get_kegiatan(){
		if ($_POST['program']!='' && $_POST['program']!='0') //$_POST['first_select'] is the post variable you sent via AJAX call
        {
        	$program = $_POST['program'];
			$data = $this->pencarian_model->get_kegiatan($program);
			$options.= '<option value="0">-- Pilih Semua --</option>';
			foreach ($data->result() as $row)
				{
					$options.= '<option value="'.$row->IDKEGIATAN.'" class="dynamic">'.$row->DESKRIPSI.'</option>';
				}        
			echo $options;
        }
		else {
		echo '<option value="0">-- Pilih Semua --</option>';}
	}
	
	function get_sasaran_keg(){
		if ($_POST['kegiatan']!='' && $_POST['kegiatan']!='0') //$_POST['first_select'] is the post variable you sent via AJAX call
        {
        	$kegiatan = $_POST['kegiatan'];
			$data = $this->pencarian_model->get_sasaran_keg($kegiatan);
			$options.= '<option value="0">-- Pilih Semua --</option>';
			foreach ($data->result() as $row)
				{
					$options.= '<option value="'.$row->IDSASARAN_KEG.'" class="dynamic">'.$row->DESKRIPSI.'</option>';
				}        
			echo $options;
        }
		else {
		echo '<option value="0">-- Pilih Semua --</option>';}
	}
	
	function get_indikator_keg(){
		if ($_POST['sasaran_keg']!='' && $_POST['sasaran_keg']!='0') //$_POST['first_select'] is the post variable you sent via AJAX call
        {
        	$sasaran_keg = $_POST['sasaran_keg'];
			$data = $this->pencarian_model->get_indikator_keg($sasaran_keg);
			$options.= '<option value="0">-- Pilih Semua --</option>';
			foreach ($data->result() as $row)
				{
					$options.= '<option value="'.$row->IDINDIKATOR_KEG.'" class="dynamic">'.$row->DESKRIPSI.'</option>';
				}        
			echo $options;
        }
		else {
		echo '<option value="0">-- Pilih Semua --</option>';}
	}
	
	
	
	function cek_validasi() {	
			// Setting Rules
			$this->form_validation->set_rules('tahun', 'Tahun Anggaran', 'callback_cek_dropdown');
			$this->form_validation->set_rules('target_prog', 'Target Indikator(Program)', 'required|numeric');
			$this->form_validation->set_rules('real_prog', 'Realisasi Indikator(Program)', 'required|numeric');
			$this->form_validation->set_rules('target_keg', 'Target Indikator(Kegiatan)', 'required|numeric');
			$this->form_validation->set_rules('real_keg', 'Realisasi Indikator(Kegiatan)', 'required|numeric');
			
			
			// Setting Error Message
			$this->form_validation->set_message('required', 'Kolom %s harus diisi!!');
			$this->form_validation->set_message('numeric', 'Kolom %s harus diisi dengan karakter angka saja, desimal menggunakan titik (.)');
			$this->form_validation->set_message('is_unique', 'Data kolom %s sudah digunakan!!');
			
			// Setting Delimiter
			$this->form_validation->set_error_delimiters('<li class="error">', '</li>');
			return $this->form_validation->run();
	}
	
	
	function cek_dropdown($value){
		if($value === '0'){
			$this->form_validation->set_message('cek_dropdown', 'Kolom %s harus diisi!!');
			return FALSE;
		}
		else{
			return TRUE;
		}
	}
	
	function cari()
	{
		$id_anggaran = $this->input->post('tahun');
		$id_program = $this->input->post('program');
		
		$id_sasaran = $this->input->post('sasaran_prog');
		$id_indikator = $this->input->post('indikator_prog');
		
		//program
		$target = $this->input->post('target_prog');
		$realisasi = $this->input->post('real_prog');
		$operasi_t = $this->input->post('nilai_prog_ind');
		$operasi_r = $this->input->post('nilai_prog_real');
		
		
		//kegiatan
		$id_kegiatan = $this->input->post('kegiatan');
		$id_sasaran_keg = $this->input->post('sasaran_keg');
		$id_indikator_keg = $this->input->post('indikator_keg');
		
		$target_keg = $this->input->post('target_keg');
		$operasi_t_keg = $this->input->post('nilai_keg_ind');
		
		$realisasi_keg = $this->input->post('real_keg');
		$operasi_r_keg = $this->input->post('nilai_keg_real');
		
		
		if($id_program==0){
			$data['deskripsi'] = 'Semua Program';
			$record_program = $this->pencarian_model->get_tahun_anggaran($id_anggaran);
			foreach ($record_program->result() as $prog){
					$data['tahun'] = $prog->TAHUN;
				}
		}
		else if($id_program!=0){
			$record_program = $this->pencarian_model->get_programID($id_program);
				foreach ($record_program->result() as $prog){
					$data['tahun'] = $prog->TAHUN;
					$data['deskripsi'] = $prog->DESKRIPSI;
				}
		}
		$menteri = $this->user_man_model->get_menteri()->row();
		$data['nama_menteri'] = $menteri->NAMA;
		$today = date("Y-m-d");
		$data['tgl_sekarang'] = $this->format_tanggal($today);
		$data['tabel'] = $this->tabel_data($id_anggaran, $id_program, $id_sasaran, $id_indikator, $target, $realisasi, $operasi_t, $operasi_r);
		
		//generate data kegiatan
		$data['tabel_keg'] = $this->tabel_data_keg($id_anggaran, $id_program, $id_kegiatan, $id_sasaran_keg, $id_indikator_keg, $target_keg, $operasi_t_keg, $realisasi_keg, $operasi_r_keg);
		
		
		//setting tanda untuk Program
		
		$data['target'] = $target;
		$data['realisasi'] = $realisasi;
		if($operasi_t==1){
		$data['operasi_t'] = ">=";
		}
		else if($operasi_t==2){
		$data['operasi_t'] = "=";
		}
		else if($operasi_t==3){
		$data['operasi_t'] = "<=";
		}
		
		
		if($operasi_r==1){
		$data['operasi_r'] = ">=";
		}
		else if($operasi_r==2){
		$data['operasi_r'] = "=";
		}
		else if($operasi_r==3){
		$data['operasi_r'] = "<=";
		}
		
		
		
		
		//setting tanda untuk Kegiatan
		if($id_kegiatan==0){
			$data['nama_kegiatan'] = 'Semua Kegiatan';
		}
		$record_kegiatan = $this->pencarian_model->get_one_kegiatan($id_kegiatan);
			foreach ($record_kegiatan->result() as $keg){
				$data['nama_kegiatan'] = $keg->DESKRIPSI;
			}
		
		
		$data['target_keg'] = $target_keg;
		$data['realisasi_keg'] = $realisasi_keg;
		if($operasi_t_keg==1){
		$data['operasi_t_keg'] = ">=";
		}
		else if($operasi_t_keg==2){
		$data['operasi_t_keg'] = "=";
		}
		else if($operasi_t_keg==3){
		$data['operasi_t_keg'] = "<=";
		}
		
		
		if($operasi_r_keg==1){
		$data['operasi_r_keg'] = ">=";
		}
		else if($operasi_r_keg==2){
		$data['operasi_r_keg'] = "=";
		}
		else if($operasi_r_keg==3){
		$data['operasi_r_keg'] = "<=";
		}
		
		
		$this->load->view('hasil_pencarian',$data);
		
	}
	
	
	 
    
	function tabel_data($id_anggaran, $id_program, $id_sasaran, $id_indikator, $target, $realisasi, $operasi_t, $operasi_r)
	{
		$abjad = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
		$isi_data = ""; 
		$no = 0;
		$no_ind = 1;
		$id_prog = 0;
		$id_sasaran_prog = 0;
		$jml_sasaran = 0;
		$jml_ind = 0;
		$first_sasaran = TRUE;
		$first_ind = TRUE;
		
		
		
		$record_indikator_parent = $this->pencarian_model->get_sasaran_indikator($id_sasaran, $id_indikator, $id_anggaran, $id_program, $operasi_t, $target);
		if($record_indikator_parent->num_rows()>0) {
			foreach ($record_indikator_parent->result() as $indikator_p) {
			
				//program------------------------------------------
				if($id_prog == $indikator_p->P_IDPROGRAM){
					$first_sasaran = FALSE;
				}else{
					$id_prog = $indikator_p->P_IDPROGRAM;
					$record_sasaran = $this->pencarian_model->get_jml_sasaran($id_prog);
					$jml_sasaran = $record_sasaran->num_rows();
					$first_sasaran = TRUE;
					
				}
				
				//sasaran--------------------------------------------
				if($id_sasaran_prog == $indikator_p->IDSASARAN_PROG){
					$first_ind = FALSE;
				}else{
					$first_ind = TRUE;
					$id_sasaran_prog = $indikator_p->IDSASARAN_PROG;
					$record_indikator = $this->pencarian_model->get_jml_indikator($id_sasaran_prog);
					$jml_ind = $record_indikator->num_rows();
					$no++;
					$no_ind = 1;
				}
				
				$desk_prog = $indikator_p->P_DESKRIPSI;
				$desk_sasaran_prog = $indikator_p->S_DESKRIPSI;
				$id_indikator = $indikator_p->IDINDIKATOR_PROG;
				$deskripsi_indikator = $indikator_p->DESKRIPSI;
				$target_indikator = $indikator_p->TARGET_DEC;
				
				$volume1 = 0;
				$persen1 = 0;
				$volume2 = 0;
				$persen2 = 0;
				$volume3 = 0;
				$persen3 = 0;
				$volume4 = 0;
				$persen4 = 0;
				
				$record_indikator_child = $this->pencarian_model->get_indikator_child($id_indikator);
				if($record_indikator_child->num_rows() == 0) {
					$record_real_ind_p = $this->pencarian_model->get_real_ind_prog($id_indikator, $realisasi, $operasi_r);
					if($record_real_ind_p->num_rows()>0) {
						foreach ($record_real_ind_p->result() as $real_ind_p) {			
							if($real_ind_p->BULAN == 3){
								$volume1 = $real_ind_p->VOLUME;
								$persen1 = $real_ind_p->PERSENTASE;
							}else if($real_ind_p->BULAN == 6){
								$volume2 = $real_ind_p->VOLUME;
								$persen2 = $real_ind_p->PERSENTASE;
							}else if($real_ind_p->BULAN == 9){
								$volume3 = $real_ind_p->VOLUME;
								$persen3 = $real_ind_p->PERSENTASE;
							}else if($real_ind_p->BULAN == 12){
								$volume4 = $real_ind_p->VOLUME;
								$persen4 = $real_ind_p->PERSENTASE;
							}							
						}
					}
					
					$isi_data .= $this->isi_data($first_ind,$first_sasaran,$jml_sasaran,$jml_ind,$no,$desk_prog,$desk_sasaran_prog,$no_ind,$deskripsi_indikator,$target_indikator,$volume1,$persen1,$volume2,$persen2,$volume3,$persen3,$volume4,$persen4);
				}else{
					
					$isi_data .= $this->isi_data($first_ind,$first_sasaran,$jml_sasaran,$jml_ind,$no,$desk_prog,$desk_sasaran_prog,$no_ind,$deskripsi_indikator,$target_indikator,'','','','','','','','');
					$no_ind_c = 0;
					foreach ($record_indikator_child->result() as $indikator_c) {
						$first_sasaran = FALSE;
						$first_ind = FALSE;
						$id_indikator = $indikator_c->IDINDIKATOR_PROG;
						$deskripsi_indikator = $indikator_c->DESKRIPSI;
						$target_indikator = $indikator_c->TARGET_DEC;	
								
						$record_real_ind_c = $this->pencarian_model->get_real_ind_prog($id_indikator, $realisasi, $operasi_r);
					if($record_real_ind_c->num_rows()>0) {
						foreach ($record_real_ind_c->result() as $real_ind_c) {			
							if($real_ind_c->BULAN == 3){
								$volume1 = $real_ind_c->VOLUME;
								$persen1 = $real_ind_c->PERSENTASE;
							}else if($real_ind_c->BULAN == 6){
								$volume2 = $real_ind_c->VOLUME;
								$persen2 = $real_ind_c->PERSENTASE;
							}else if($real_ind_c->BULAN == 9){
								$volume3 = $real_ind_c->VOLUME;
								$persen3 = $real_ind_c->PERSENTASE;
							}else if($real_ind_c->BULAN == 12){
								$volume4 = $real_ind_c->VOLUME;
								$persen4 = $real_ind_c->PERSENTASE;
							}							
						}
					}
					
					$isi_data .= $this->isi_data($first_ind,$first_sasaran,$jml_sasaran,$jml_ind,$no,$desk_prog,$desk_sasaran_prog,$abjad[$no_ind_c],$deskripsi_indikator,$target_indikator,$volume1,$persen1,$volume2,$persen2,$volume3,$persen3,$volume4,$persen4);
					$no_ind_c++;
					}
				}
				$no_ind++;
			}
		}	
		return $isi_data;
	}
	
	function isi_data($first_ind,$first_sasaran,$jml_sasaran,$jml_ind,$no,$desk_prog,$sasaran,$no_ind,$indikator,$target,$volume1,$persen1,$volume2,$persen2,$volume3,$persen3,$volume4,$persen4){
		if($first_sasaran == TRUE){
			$isi_data = "<tr>
					<td rowspan=\"".$jml_sasaran."\">".$desk_prog."</td>
					<td rowspan=\"".$jml_ind."\">".$sasaran."</td>
					<td>".$no_ind.") ".$indikator."</td>
					<td align='center'>".number_format($target, null, ',', '.')."</td>
					<td align='center'>".$volume1."</td>
					<td align='center'>".$persen1."</td>
					<td align='center'>".$volume2."</td>
					<td align='center'>".$persen2."</td>
					<td align='center'>".$volume3."</td>
					<td align='center'>".$persen3."</td>
					<td align='center'>".$volume4."</td>
					<td align='center'>".$persen4."</td>
				</tr>";		
		}
		
		
		else{
			if($first_ind == TRUE){
				$isi_data = "<tr>
					<td rowspan=\"".$jml_ind."\">".$sasaran."</td>
					<td>".$no_ind.") ".$indikator."</td>
					<td align='center'>".number_format($target, null, ',', '.')."</td>
					<td align='center'>".$volume1."</td>
					<td align='center'>".$persen1."</td>
					<td align='center'>".$volume2."</td>
					<td align='center'>".$persen2."</td>
					<td align='center'>".$volume3."</td>
					<td align='center'>".$persen3."</td>
					<td align='center'>".$volume4."</td>
					<td align='center'>".$persen4."</td>
				</tr>";
			}
			
			else{
				$isi_data = "<tr>
					<td>".$no_ind.") ".$indikator."</td>
					<td align='center'>".number_format($target, null, ',', '.')."</td>
					<td align='center'>".$volume1."</td>
					<td align='center'>".$persen1."</td>
					<td align='center'>".$volume2."</td>
					<td align='center'>".$persen2."</td>
					<td align='center'>".$volume3."</td>
					<td align='center'>".$persen3."</td>
					<td align='center'>".$volume4."</td>
					<td align='center'>".$persen4."</td>
				</tr>";
			}
			
		}		
		return $isi_data;
	}
  
  function format_tanggal($tanggal_x){
		$date = explode ("-",$tanggal_x);
		if($date[0]!='' && $date[1]!='' && $date[2]!=''){
		$tahun = $date[0];
		$tanggal = $date[2]; 
		switch ($date[1]) {
			case '01':
				$bulan='Januari';
				break;
			case '02':
				$bulan='Februari';
				break;
			case '03':
				$bulan='Maret';
				break;
			case '04':
				$bulan='April';
				break;
			case '05':
				$bulan='Mei';
				break;
			case '06':
				$bulan='Juni';
				break;
			case '07':
				$bulan='Juli';
				break;
			case '08':
				$bulan='Agustus';
				break;
			case '09':
				$bulan='September';
				break;
			case '10':
				$bulan='Oktober';
				break;
			case '11':
				$bulan='November';
				break;
			case '12':
				$bulan='Desember';
				break;		
		}
		$tanggal_indo = $tanggal." ".$bulan." ".$tahun;
		}else{
		$tanggal_indo = '';
		}		
		return $tanggal_indo;
	}
	
	
	
	
	
	//----------------------KEGIATAN---------------------------------\\
	function tabel_data_keg($id_anggaran, $id_program, $id_kegiatan, $id_sasaran_keg, $id_indikator_keg, $target_keg, $operasi_t_keg, $realisasi_keg, $operasi_r_keg)
	{
		$abjad = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
		$isi_data = ""; 
		$no = 0;
		$no_ind = 1;
		$id_prog = 0;
		$id_keg = 0;
		$id_sasaran_keg = 0;
		$jml_sasaran = 0;
		$jml_ind = 0;
		$jml_keg=0;
		$first_kegiatan = TRUE;
		$first_sasaran = TRUE;
		$first_ind = TRUE;
		
		
		$record_indikator_parent = $this->pencarian_model_keg->get_sasaran_indikator($id_anggaran, $id_program, $id_sasaran_keg, $id_indikator_keg, $id_kegiatan, $operasi_t_keg, $target_keg);
		if($record_indikator_parent->num_rows()>0) {
			foreach ($record_indikator_parent->result() as $indikator_p) {
				//program------------------------------------------
				if($id_prog == $indikator_p->P_IDPROGRAM){
					$first_sasaran = FALSE;
				}else{
					$id_prog = $indikator_p->P_IDPROGRAM;
					$record_sasaran = $this->pencarian_model_keg->get_jml_sasaran($id_prog);
					$jml_sasaran = $record_sasaran->num_rows();
					$first_sasaran = TRUE;
					
				}
				
				
				//kegiatan-----------------------------------------
				if($id_keg == $indikator_p->K_IDKEGIATAN){
					$first_kegiatan = FALSE;
				}else{
					$id_keg = $indikator_p->K_IDKEGIATAN;
					$record_kegiatan = $this->pencarian_model_keg->get_jml_keg($id_keg);
					$jml_keg = $record_kegiatan->num_rows();
					$first_kegiatan = TRUE;
					
				}
				
				
				
				//sasaran keg--------------------------------------------
				if($id_sasaran_keg == $indikator_p->IDSASARAN_KEG){
					$first_ind = FALSE;
				}else{
					$first_ind = TRUE;
					$id_sasaran_keg = $indikator_p->IDSASARAN_KEG;
					$record_indikator = $this->pencarian_model_keg->get_jml_indikator($id_sasaran_keg);
					$jml_ind = $record_indikator->num_rows();
					$no++;
					$no_ind = 1;
				}
				
				$desk_prog = $indikator_p->P_DESKRIPSI;
				$desk_kegiatan = $indikator_p->K_DESKRIPSI;
				$desk_sasaran_keg = $indikator_p->S_DESKRIPSI;
				$id_indikator = $indikator_p->IDINDIKATOR_KEG;
				$deskripsi_indikator = $indikator_p->DESKRIPSI;
				$target_indikator = $indikator_p->TARGET_DEC;
				
				$volume1 = 0;
				$persen1 = 0;
				$volume2 = 0;
				$persen2 = 0;
				$volume3 = 0;
				$persen3 = 0;
				$volume4 = 0;
				$persen4 = 0;
				
				$record_indikator_child = $this->pencarian_model_keg->get_indikator_child($id_indikator);
				if($record_indikator_child->num_rows() == 0) {
					//realisasi kegiatan
					//$realisasi_keg = 100;//$this->input->post('realisasi_keg');
					//$operasi_r_keg = 1;//$this->input->post('tanda_realisasi_keg');
					
					
					$record_real_ind_p = $this->pencarian_model_keg->get_real_ind_keg($id_indikator, $realisasi_keg, $operasi_r_keg);
					if($record_real_ind_p->num_rows()>0) {
						foreach ($record_real_ind_p->result() as $real_ind_p) {			
							if($real_ind_p->BULAN == 3){
								$volume1 = $real_ind_p->VOLUME;
								$persen1 = $real_ind_p->PERSENTASE;
							}else if($real_ind_p->BULAN == 6){
								$volume2 = $real_ind_p->VOLUME;
								$persen2 = $real_ind_p->PERSENTASE;
							}else if($real_ind_p->BULAN == 9){
								$volume3 = $real_ind_p->VOLUME;
								$persen3 = $real_ind_p->PERSENTASE;
							}else if($real_ind_p->BULAN == 12){
								$volume4 = $real_ind_p->VOLUME;
								$persen4 = $real_ind_p->PERSENTASE;
							}							
						}
					}
					$isi_data .= $this->isi_data_keg($first_ind,$first_sasaran,$first_kegiatan,$jml_sasaran,$jml_ind,$jml_keg,$no,$desk_prog,$desk_kegiatan,$desk_sasaran_keg,$no_ind,$deskripsi_indikator,$target_indikator,$volume1,$persen1,$volume2,$persen2,$volume3,$persen3,$volume4,$persen4);
				}else{
					$isi_data .= $this->isi_data_keg($first_ind,$first_sasaran,$first_kegiatan,$jml_sasaran,$jml_ind,$jml_keg,$desk_prog,$desk_kegiatan,$no,$desk_sasaran_keg,$no_ind,$deskripsi_indikator,$target_indikator,'','','','','','','','');
					$no_ind_c = 0;
					foreach ($record_indikator_child->result() as $indikator_c) {
						$first_sasaran = FALSE;
						$first_kegiatan = FALSE;
						$first_ind = FALSE;
						$id_indikator = $indikator_c->IDINDIKATOR_KEG;
						$deskripsi_indikator = $indikator_c->DESKRIPSI;
						$target_indikator = $indikator_c->TARGET_DEC;	
								
						$record_real_ind_c = $this->pencarian_model_keg->get_real_ind_keg($id_indikator);
					if($record_real_ind_c->num_rows()>0) {
						foreach ($record_real_ind_c->result() as $real_ind_c) {			
							if($real_ind_c->BULAN == 3){
								$volume1 = $real_ind_c->VOLUME;
								$persen1 = $real_ind_c->PERSENTASE;
							}else if($real_ind_c->BULAN == 6){
								$volume2 = $real_ind_c->VOLUME;
								$persen2 = $real_ind_c->PERSENTASE;
							}else if($real_ind_c->BULAN == 9){
								$volume3 = $real_ind_c->VOLUME;
								$persen3 = $real_ind_c->PERSENTASE;
							}else if($real_ind_c->BULAN == 12){
								$volume4 = $real_ind_c->VOLUME;
								$persen4 = $real_ind_c->PERSENTASE;
							}							
						}
					}
					$isi_data .= $this->isi_data_keg($first_ind,$first_sasaran,$first_kegiatan,$jml_sasaran,$jml_ind,$jml_keg,$no,$desk_prog,$desk_kegiatan,$desk_sasaran_keg,$abjad[$no_ind_c],$deskripsi_indikator,$target_indikator,$volume1,$persen1,$volume2,$persen2,$volume3,$persen3,$volume4,$persen4);
					$no_ind_c++;
					}
				}
				$no_ind++;
			}
		}	
		return $isi_data;
	}
	
	function isi_data_keg($first_ind,$first_sasaran,$first_kegiatan,$jml_sasaran,$jml_ind,$jml_keg,$no,$desk_prog,$desk_kegiatan,$sasaran,$no_ind,$indikator,$target,$volume1,$persen1,$volume2,$persen2,$volume3,$persen3,$volume4,$persen4){
		if($first_sasaran == TRUE){
			$isi_data = "<tr>
					<td rowspan=\"".$jml_sasaran."\">".$desk_prog."</td>
					<td rowspan=\"".$jml_keg."\">".$desk_kegiatan."</td>
					<td rowspan=\"".$jml_ind."\">".$sasaran."</td>
					<td>".$no_ind.") ".$indikator."</td>
					<td align='center'>".number_format($target, null, ',', '.')."</td>
					<td align='center'>".$volume1."</td>
					<td align='center'>".$persen1."</td>
					<td align='center'>".$volume2."</td>
					<td align='center'>".$persen2."</td>
					<td align='center'>".$volume3."</td>
					<td align='center'>".$persen3."</td>
					<td align='center'>".$volume4."</td>
					<td align='center'>".$persen4."</td>
				</tr>";
		
		}else{
			if($first_kegiatan == TRUE){
				$isi_data = "<tr>
							<td rowspan=\"".$jml_keg."\">".$desk_kegiatan."</td>
							
							<td rowspan=\"".$jml_ind."\">".$sasaran."</td>
							<td>".$no_ind.") ".$indikator."</td>
							<td align='center'>".number_format($target, null, ',', '.')."</td>
							<td align='center'>".$volume1."</td>
							<td align='center'>".$persen1."</td>
							<td align='center'>".$volume2."</td>
							<td align='center'>".$persen2."</td>
							<td align='center'>".$volume3."</td>
							<td align='center'>".$persen3."</td>
							<td align='center'>".$volume4."</td>
							<td align='center'>".$persen4."</td>
						</tr>";
				}else{
					if($first_ind == TRUE){
						$isi_data = "<tr>
									<td rowspan=\"".$jml_ind."\">".$sasaran."</td>
									<td>".$no_ind.") ".$indikator."</td>
									<td align='center'>".number_format($target, null, ',', '.')."</td>
									<td align='center'>".$volume1."</td>
									<td align='center'>".$persen1."</td>
									<td align='center'>".$volume2."</td>
									<td align='center'>".$persen2."</td>
									<td align='center'>".$volume3."</td>
									<td align='center'>".$persen3."</td>
									<td align='center'>".$volume4."</td>
									<td align='center'>".$persen4."</td>
								</tr>";
						}else{
							$isi_data = "<tr>
										<td>".$no_ind.") ".$indikator."</td>
										<td align='center'>".number_format($target, null, ',', '.')."</td>
										<td align='center'>".$volume1."</td>
										<td align='center'>".$persen1."</td>
										<td align='center'>".$volume2."</td>
										<td align='center'>".$persen2."</td>
										<td align='center'>".$volume3."</td>
										<td align='center'>".$persen3."</td>
										<td align='center'>".$volume4."</td>
										<td align='center'>".$persen4."</td>
									</tr>";
						}
					}
			}
			return $isi_data;		
	}
	
	
	
	
  
}
?>